View Javadoc
1 /*** 2 * XMLSummary 3 * 4 * This is a summary coverage report 5 * in XML. 6 * 7 * Report looks like: 8 * <PRE> 9 * <?xml version="1.0"?> 10 * 11 * <CoverageReport date="2001/12/29 10:30AM"> 12 * <Class name="..."> 13 * <Method name="doSomething()V"> 14 * <Coverage metric="stmt" percent="43.8" /> 15 * </Method> 16 * ... 17 * </Class> 18 * ... 19 * </CoverageReport> 20 *</pre> 21 */ 22 23 package junit.quilt.reports; 24 25 import java.net.URLEncoder; 26 27 import java.io.OutputStream; 28 import java.io.OutputStreamWriter; 29 import java.io.PrintWriter; 30 import java.io.IOException; 31 32 import java.text.DateFormat; 33 import java.text.SimpleDateFormat; 34 import java.util.Date; 35 import java.util.Enumeration; 36 37 import java.util.Iterator; 38 import java.util.Set; 39 import java.util.Map; 40 41 import javax.swing.tree.*; 42 43 import junit.quilt.framework.*; 44 45 public class XMLSummary 46 extends Object 47 implements Report 48 { 49 public void writeNode( PrintWriter out, 50 QuiltRegistry registry, 51 int level, 52 String levels[], 53 TreeNode nodes[]) { 54 55 TreeNode node = nodes[level]; 56 57 indentTo(out, level); 58 out.println("<" + levels[level] + 59 " name=\"" + 60 URLEncoder.encode( nodes[level].toString()) 61 + "\">"); 62 63 if (level == levels.length - 1) { // Base Case 64 TreePath tp = new TreePath( nodes ); 65 QuiltCollector collect = registry.getCollector( tp ); 66 if (collect != null) { 67 Set capabilities = collect.getCapabilities(); 68 Iterator caps = capabilities.iterator(); 69 70 while (caps.hasNext()) { 71 String cap = (String) caps.next(); 72 73 Set all = collect.getAll(cap); 74 Set covered = collect.getCovered(cap); 75 76 indentTo(out, level + 1); 77 double perc = 100.0 * ((double) covered.size() / 78 (double) all.size()); 79 out.println("<Coverage " + 80 "metric=\"" + cap + "\" " + 81 "total=\"" + all.size() + "\" " + 82 "covered=\"" + covered.size() + "\" " + 83 "percent=\"" + perc + "\" />"); 84 } 85 } 86 } else { 87 Enumeration children = node.children(); 88 while (children.hasMoreElements()) { 89 TreeNode next = (TreeNode) children.nextElement(); 90 nodes[level + 1] = next; 91 writeNode(out, registry, level + 1, levels, nodes); 92 } 93 } 94 95 indentTo(out, level); 96 out.println("</" + levels[level] + ">"); 97 } 98 99 100 public void writeReport( OutputStream out, 101 QuiltRegistry registry ) 102 throws IOException 103 { 104 String levels[] = registry.getLevels(); 105 106 PrintWriter pw = new PrintWriter( new OutputStreamWriter( out ) ); 107 pw.println("<?xml version=\"1.0\"?>"); 108 pw.println("<CoverageReport>"); 109 110 TreeNode nodes[] = new TreeNode[levels.length]; 111 nodes[0] = registry.getContents(); 112 113 writeNode( pw, registry, 0, levels, nodes ); 114 pw.println("</CoverageReport>"); 115 pw.flush(); 116 } 117 118 private void indentTo(PrintWriter out, int size) { 119 for (int j = 0; j < size + 1; j++) { 120 out.print(" "); 121 } 122 } 123 } 124

This page was automatically generated by Maven